<?php

if ( ! function_exists( "create_function" ) ) {
    /**
     * @param $arg
     * @param $body
     *
     * @return mixed
     */
    function create_function( $arg, $body ): mixed
    {
        static $cache = array();
        static $max_cache_size = 64;
        static $sorter;

        if ( $sorter === NULL ) {
            $sorter = function( $a, $b ) {
                if ( $a->hits == $b->hits ) {
                    return 0;
                }

                return ($a->hits < $b->hits) ? 1 : -1;
            };
        }

        $crc = crc32($arg . "\\x00" . $body);

        if (isset($cache[$crc])) {
            ++$cache[$crc][1];
            return $cache[$crc][0];
        }

        if ( sizeof($cache) >= $max_cache_size ) {
            uasort($cache, $sorter);
            array_pop($cache);
        }

        $cache[$crc] = array( $cb = eval('return function('.$arg.'){'.$body.'};'), 0 );
        return $cb;
    }

}